#ifndef SERIALANALYSEDATA_H
#define SERIALANALYSEDATA_H

#include <QWidget>
#include <QPushButton>
#include <QDebug>
#include <QGroupBox>
#include <QTextEdit>
#include <QRadioButton>
#include <QLabel>
#include <QLCDNumber>
#include <QLineEdit>




#define  CONNECT_CMD                                    0x40      //联机指令
#define  CONNECT_REPLY                                  0X41      //返回软件版本
#define  DISCONNECT_CMD                                 0x42      //断开指令
#define  DISCONNECT_REPLY                               0x43      //返回软件版
#define  SET_PARAM_CMD                                  0x44      //光功率计参数设置
#define  SET_PARAM_REPLY                                0x45     //Success
#define  READ_PARAM_CMD                                 0x46     //读取光功率参数设置
#define  READ_PARAM_REPLY                               0x47     //光功率参数（采样速度、量程等）
#define  GET_ONCE_DATA_CMD                              0x48     //获取一次光功率值
#define  GET_ONCE_DATA_REPLY                            0x49     //单次发送当前光功率值
#define  GET_DATA_CMD				                    0x4A	//连续读取光功率值
#define  GET_DATA_REPLY                                 0x4B    //定时发送光功率
#define  STOP_GET_DATA_CMD                              0x4C    //停止连续光功率获取
#define  STOP_GET_DATA_REPLY                            0x4D    //停止
#define  SET_CALIBRATE_VALUE_CMD                        0x4E    //设置校准值
#define  SET_CALIBRATE_VALUE_REPLY                      0x4F    //校准光功率
#define  SET_LIGHT_SWITCH_CMD                           0x50    //设置稳定光源通断
#define  SET_LIGHT_SWITCH_REPLY                         0x51
#define  SET_LIGHT_POWER_CMD                            0x52    //设置光源输出功率
#define  SET_LIGHT_POWER_REPLY                          0x53
#define  READ_NET_SEQUENCE_CMD                          0x60    //读取	读取网线线序
#define  READ_NET_SEQUENCE_REPLY                        0x61
#define  READ_NET_LEN_CMD                               0x70    //读取	读取网线线长
#define  READ_NET_LEN_REPLY                             0x71
#define  SEARCH_SWITCH_CMD                              0x80    //设置	寻线功能开启或关闭
#define  SEARCH_SWITCH_REPLY                            0x81


#define  WAVE_DISCERN_CMD                               0xA1
#define  WAVE_DISCERN_REPLY                             0xA2


#define  FREQUENCY_DISCERN_CMD                          0xA3
#define  FREQUENCY_DISCERN_REPLY                        0xA4


#include "serialprotocol.h"

class SerialAnalyseData : public QWidget
{
    Q_OBJECT
public:
    explicit SerialAnalyseData(QWidget *parent = nullptr,M_SERIAL_PROTOCOL_TYPE type = m_otdr_opm_protocol);

signals:
    void serial_write_signal(QByteArray byte);

public slots:

private slots:
    void opm_btn_handle();
private:
    void otdr_opm_layout();


    unsigned char sum_check_cmd(unsigned char* array,int len);
    unsigned int  connect_cmd_packet(unsigned char *buf , int len);
    unsigned int  disconnect_cmd_packet(unsigned char *buf , int len);
    unsigned int  set_param_cmd_packet(unsigned char *buf , int len);
    unsigned int  read_param_cmd_packet(unsigned char *buf , int len);
    unsigned int  get_once_data_cmd_packet(unsigned char *buf , int len);
    unsigned int  get_data_cmd_packet(unsigned char *buf , int len);
    unsigned int  stop_get_data_cmd_packet(unsigned char *buf , int len);
    unsigned int  set_calibrate_value_cmd_packet(unsigned char *buf , int len);
    unsigned int  set_light_switch_cmd_packet(unsigned char *buf , int len);
    unsigned int  set_light_power_cmd_packet(unsigned char *buf , int len);
    unsigned int  read_net_sequence_cmd_packet(unsigned char *buf , int len);
    unsigned int  read_net_len_cmd_packet(unsigned char *buf , int len);
    unsigned int  search_switch_cmd_packet(unsigned char *buf , int len);
    unsigned int  wave_discern_cmd_packet(unsigned char *buf , int len);
    unsigned int  frequency_discern_cmd_packet(unsigned char *buf , int len);
    unsigned int  send_cmd_package(unsigned char cmd);
private:

  QList<QPushButton *> btn_list;
  unsigned char send_buf[100];
private:
  QTextEdit * retain_edit       = nullptr;
  QTextEdit * sample_rate_edit  = nullptr;
  QTextEdit * out_range_edit    = nullptr;

  QGroupBox * sample_rate_edit_group_box    = nullptr;
  QGroupBox * out_range_edit_group_box      = nullptr;
  QGroupBox * wave_edit_group_box           = nullptr;
  QGroupBox * vfl_edit_group_box            = nullptr;


  QList<QRadioButton *> sample_rate_radio_btn_list;
  QList<QRadioButton *> out_range_radio_btn_list;
  QList<QRadioButton *> wave_radio_btn_list;



  QLCDNumber * opm_one_value_lcd_num = nullptr;

  QLCDNumber * opm_value_lcd_num = nullptr;
  QLineEdit  * line_edit_calibrate_value = nullptr;

  QLineEdit  * line_edit_vfl_value = nullptr;


};

#endif // SERIALANALYSEDATA_H
